﻿package Welsy4.Connect.commands
{
	import com.adobe.cairngorm.commands.SequenceCommand;
	import flash.net.URLVariables;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.IResponder;
	import mx.controls.Alert;
	
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	
	import Welsy4.Connect.business.PermissionDelegate;
	import Welsy4.Connect.events.ChainEvent;
	import Welsy4.Connect.events.ResponseEvent;
	import Welsy4.Connect.model.ConnectModel;
	import Welsy4.Connect.vo.HttpServiceHandler;
	import Welsy4.Connect.vo.Meeting;
	
	
	
	public class AddMeetingParticipantsCommand extends SequenceCommand implements Command, IResponder
	{
		
		public function AddMeetingParticipantsCommand() 
		{
			
		}
		override public function execute(event:CairngormEvent):void {
			ConnectModel.getInstance().addQueue("AddMeetingParticipantsCommand.execute ");
			
			this.nextEvent = ChainEvent(event).nextChainedEvent;
			
			var publicPermissionRequest:URLVariables = new URLVariables();

			// set request GET params
			publicPermissionRequest.action = "permissions-update";
			publicPermissionRequest.decode("acl-id=" + ConnectModel.getInstance().lastMeetingFound.sco_id);
			publicPermissionRequest.decode("principal-id=" + ConnectModel.getInstance().lastUserFound.principal_id);
			publicPermissionRequest.decode("permission-id=" + ConnectModel.getInstance().lastUserFound.permission);
						
			// set Delegate to send data
			var permissionDelegate:PermissionDelegate = new PermissionDelegate(this);
			permissionDelegate.setPermission(publicPermissionRequest);
			
		}
		
		public function result(event:Object):void {
			
			// listen for ok result
		    ConnectModel.getInstance().addQueue("AddMeetingParticipantsCommand.result " + event.result);
		    
			this.executeNextCommand();
		}
		
		public function fault(event:Object):void {
			ConnectModel.getInstance().addQueue("AddMeetingParticipantsCommand.fault");
			CairngormEventDispatcher.getInstance().dispatchEvent(new ResponseEvent(ResponseEvent.ERROR,false,ResponseEvent.CONNECTION));
		}
	}
	
}